#encoding:utf-8

'''
data=2017/2/6 下午4:18
__author__='binpo',
author_email='binpocn@163.com',
'''

import requests
import json
def get_current_price():
    req = requests.get('https://api.coinmarketcap.com/v1/ticker/e-dinar-coin/')
    data = json.loads(req.text)
    current_price = float(data[0].get('price_usd'))
    return current_price

appkey='487c2384f27b5c8c7664a8236b1ea9b7'
def get_usd_cyh():
        url = "http://web.juhe.cn:8080/finance/exchange/frate"
        params = {
            "key": appkey
        }
        req = requests.get(url,params)
        content = req.text
        # print content
        res = json.loads(content)
        data = res.get('result')[0]
        if data.get('data8').get('code')=='USDCNY':
            return data.get('data8').get('buyPic')


import oss2

AccessKeyId='LTAIfMNYOKAyTDJ3'
AccessKeySecret='dOOOZUuyC95ooE6iR8O3hwBooQp2Ul'
Bucket='echatcoin'
EndPoint='http://oss-cn-shanghai.aliyuncs.com'#域
ImgDomain='http://echatcoin.oss-cn-shanghai.aliyuncs.com'

auth = oss2.Auth(AccessKeyId, AccessKeySecret)
bucket = oss2.Bucket(auth, EndPoint,Bucket)

import re

RE_SPECIAL_STR = re.compile(r'[^\w.]') #特殊字符串替换

import datetime
def datetime_format(format='%Y-%m-%d %H:%M:%S',input_time=None):
    import datetime
    if not input_time:
        input_time=datetime.datetime.now()
    return datetime.datetime.strftime(input_time,format)

def upload_file(filename,file_stream):
    '''
                上传文件
    :param filename:
    :param file_stream:
    :return:
    '''
    filename= RE_SPECIAL_STR.sub('0',filename)
    #img_buffer = StringIO(io.BytesIO(file_stream))
    filename = datetime_format(format='%Y%m%d') + '/'+filename
    bucket.put_object(filename, file_stream)
    full_url = '/'.join([ImgDomain, filename])
    data = {
            'full_url': full_url,
            'filename':filename
            }
    return data

def download_file(file_name):
    remote_stream = bucket.get_object(file_name)
    return remote_stream.read()

def delete_file(filename):
    '''
    删除文件
    :param filename:
    :return:
    '''
    bucket.delete_object(filename)